home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / plan / src / daydraw.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  5KB  |  184 lines

  1. /*
  2.  * Draw the list of entries and everything in it. The list is drawn into
  3.  * an array of text and image buttons. The first row is reserved for the
  4.  * title; it cannot be pressed. This means schedule entries 0..n are drawn
  5.  * into columns 1..n+1.
  6.  *
  7.  *    draw_list(w)            Draw or redraw a list of entries
  8.  *                    into a list menu.
  9.  *    mkbuttonstring(lw, x, y)    Return a string to draw into a text
  10.  *                    button in the list menu array.
  11.  *    mknotestring(ep)        Return the string to draw into the
  12.  *                    note button in the menu list array,
  13.  *                    or into the day box in the calendar.
  14.  */
  15.  
  16. #include <time.h>
  17. #include <Xm/Xm.h>
  18. #include "cal.h"
  19.  
  20. extern struct edit    edit;        /* info about entry being edited */
  21. extern struct config    config;        /* global configuration data */
  22.  
  23. char *mkbuttonstring(), *mknotestring();
  24. extern char *mkdatestring(), *mktimestring();
  25.  
  26.  
  27. /*
  28.  * draw a list into a list popup. Always call create_sublist() for the
  29.  * menu first, so that there is something to draw. Clear now-unused rows
  30.  * under the current last row that may have been drawn earlier.
  31.  */
  32.  
  33. draw_list(w)
  34.     struct listmenu        *w;        /* draw into which menu */
  35. {
  36.     register Widget        (*wp)[SC_N];    /* button widget pointer */
  37.     struct entry        **epp;        /* entry pointer pointer */
  38.     register struct entry    *ep;        /* entry pointer */
  39.     int            n = 0;        /* entry counter */
  40.     Arg            args;        /* for toggle button */
  41.  
  42.     wp = w->entry + 1;                /* [0] is header */
  43.     if (w->sublist) {                /* draw entries */
  44.         create_entry_widgets(w, w->sublist->nentries);
  45.         wp  = w->entry + 1;
  46.         epp = w->sublist->entry;
  47.         for (n=0; n <= w->sublist->nentries; n++, wp++, epp++) {
  48.         if (edit.editing && edit.menu == w && edit.y-1 == n)
  49.             ep = &edit.entry;
  50.         else if (n < w->sublist->nentries)
  51.             ep = *epp;
  52.         else
  53.             break;
  54.         XtSetArg(args, XmNset, !ep->suspended);
  55.         XtSetValues ((*wp)[SC_ENABLE], &args, 1);
  56.  
  57.         print_button((*wp)[SC_DATE],  mkbuttonstring(w,SC_DATE,  n+1));
  58.         print_button((*wp)[SC_TIME],  mkbuttonstring(w,SC_TIME,  n+1));
  59.         print_button((*wp)[SC_LENGTH],mkbuttonstring(w,SC_LENGTH,n+1));
  60.         print_button((*wp)[SC_NOTE],  mkbuttonstring(w,SC_NOTE,  n+1));
  61.  
  62.         if (config.bigwarning)
  63.             print_button((*wp)[SC_ADVANCE],
  64.                          mkbuttonstring(w,SC_ADVANCE,n+1));
  65.         else
  66.             print_pixmap((*wp)[SC_ADVANCE],
  67.             !ep->notime && (ep->noalarm ||
  68.             ep->early_warn || ep->late_warn)  ? PIC_ADVANCE : -1);
  69.         print_pixmap((*wp)[SC_RECYCLE],
  70.             ep->rep_every || ep->rep_days ||
  71.             ep->rep_yearly ||
  72.             ep->rep_weekdays          ? PIC_RECYCLE : -1);
  73.         print_pixmap((*wp)[SC_MESSAGE],
  74.             ep->message              ? PIC_MESSAGE : -1);
  75.         print_pixmap((*wp)[SC_SCRIPT],
  76.             !ep->notime && ep->script      ? PIC_SCRIPT  : -1);
  77.         print_pixmap((*wp)[SC_MEETING],
  78.             ep->meeting              ? PIC_MEETING : -1);
  79.         print_pixmap((*wp)[SC_PRIVATE],
  80.             ep->private              ? PIC_PRIVATE  : -1);
  81.         }
  82.     }
  83.     for (; n < w->nentries; n++, wp++) {        /* draw blank rows */
  84.         XtSetArg(args, XmNset, FALSE);
  85.         XtSetValues ((*wp)[SC_ENABLE], &args, 1);
  86.         print_button((*wp)[SC_DATE],    "");
  87.         print_button((*wp)[SC_TIME],    "");
  88.         print_button((*wp)[SC_LENGTH],  "");
  89.         print_button((*wp)[SC_NOTE],    "");
  90.         print_pixmap((*wp)[SC_RECYCLE], -1);
  91.         print_pixmap((*wp)[SC_MESSAGE], -1);
  92.         print_pixmap((*wp)[SC_SCRIPT],  -1);
  93.         print_pixmap((*wp)[SC_MEETING], -1);
  94.         print_pixmap((*wp)[SC_PRIVATE], -1);
  95.         if (config.bigwarning)
  96.             print_button((*wp)[SC_ADVANCE], "");
  97.         else
  98.             print_pixmap((*wp)[SC_ADVANCE], -1);
  99.     }
  100. }
  101.  
  102.  
  103. /*
  104.  * return some sensible string representation of a button. This doesn't work
  105.  * for pixmap labels.
  106.  */
  107.  
  108. char *mkbuttonstring(lw, x, y)
  109.     struct listmenu        *lw;        /* menu the button is in */
  110.     int            x, y;        /* column and row (y >= 1) */
  111. {
  112.     static char        buf[40];    /* string representation */
  113.     register struct entry    *ep;        /* entry pointer */
  114.  
  115.     if (edit.editing && edit.menu == lw && edit.y == y)
  116.         ep = &edit.entry;
  117.     else if (!lw->sublist || y > lw->sublist->nentries)
  118.         return("");
  119.     else
  120.         ep = lw->sublist->entry[y-1];
  121.  
  122.     switch(x) {
  123.       case SC_DATE:
  124.         return(mkdatestring(ep->time));
  125.  
  126.       case SC_TIME:
  127.         return(ep->notime ? "-" : mktimestring(ep->time, FALSE));
  128.  
  129.       case SC_LENGTH:
  130.         return(ep->length > 0 && !ep->notime ?
  131.                     mktimestring(ep->length, TRUE) : "");
  132.       case SC_ADVANCE:
  133.         *buf = 0;
  134.         if (ep->notime)
  135.             break;
  136.         if (ep->early_warn)
  137.             sprintf(buf, "%d", (int)ep->early_warn/60);
  138.         if (ep->late_warn) {
  139.             if (ep->early_warn)
  140.                 strcat(buf, ", ");
  141.             sprintf(buf+strlen(buf), "%d", (int)ep->late_warn/60);
  142.         }
  143.         if (ep->noalarm) {
  144.             if (ep->early_warn || ep->late_warn)
  145.                 strcat(buf, ", ");
  146.             strcat(buf, "-");
  147.         }
  148.         break;
  149.  
  150.       case SC_NOTE:
  151.         return(mknotestring(ep));
  152.     }
  153.     return(buf);
  154. }
  155.  
  156.  
  157. /*
  158.  * return the entries's note string. This is separate from mkbuttonstring
  159.  * because it is also used to print notes into the calendar day boxes.
  160.  */
  161.  
  162. char *mknotestring(ep)
  163.     register struct entry    *ep;        /* entry pointer */
  164. {
  165.     static char        buf[256];    /* string representation */
  166.     char            *note;        /* note to print */
  167.     int            i;        /* string index */
  168.  
  169.     if ((note = ep->note)    == 0 &&
  170.         (note = ep->message) == 0 &&
  171.         (note = ep->script)  != 0)
  172.         if (note[0] == '#' && note[1] == '!') {
  173.             while (*note && *note++ != '\n');
  174.             if (!*note)
  175.                 note = ep->script;
  176.         }
  177.     i = 0;
  178.     if (note)
  179.         while (i < 255 && *note && *note != '\n')
  180.             buf[i++] = *note++;
  181.     buf[i] = 0;
  182.     return(buf);
  183. }
  184.